<script>
    //图片上传
    $('#file').change(function () {
        $('#load').css("display", "block");
        var formdData = new FormData();
        formdData.append("multipartFile", $('#file')[0].files[0]);
        $.ajax({
            url: "http://zkdcloud.cn/upload/img",
            type: "POST",
            async: true,
            data: formdData,
            async: false,
            contentType: false,
            processData: false,
            success: function (data) {

                $('#workImg').val(data);
                $('#Img').attr("src", data);
                $('#Img1').attr("src", data);
                $('#Img2').attr("src", data);
                $('#Img').css("display", "block");
                $('#UserImg').val(data);
                $('#load').css("display", "none");

            },
            error: function (data) {
                $('#load').css("display", "none");
                alert(data);

            },
        });
    })
    //上传基本信息
    $('#updateBaseInfo').click(function () {

        $.ajax({
            url: "${server}/updateBaseInfo",
            data: {
                "username": $('#username').val(),
                "sign": $('#sign').val(),
                "oldPassword": $('#oldPassword').val(),
                "password": $('#password').val(),
                "confirmPassword": $('#confirmPassword').val()
            },
            method: "POST",
            success: function (data) {
                alert(data);
                $('#oldPassword').val("");
                $('#password').val("");
                $('#confirmPassword').val("");
                window.location.reload();
            }
        })

    })
    //上传学院专业，班级
    $('#updateCollege').click(function () {
        $.ajax({
            url: "${server}/updateCollege",
            data: {
                "college": $('#college').val(),
                "major": $('#major').val(),
                "classes": $('#classes').val()
            },
            method: "POST",
            success: function (data) {
                alert(data);
                window.location.reload();
            }
        })
        return false;
    })

    //上传头像
    $('#updateHead').click(function () {
        $.ajax({
            url: "${server}/updateHead",
            data: {"UserImg": $('#UserImg').val()},
            method: "POST",
            success: function (data) {
                alert(data);
                window.location.reload();
            }
        })
        return false;
    })

    //get college

    $('#college').hover(function () {

        $.ajax({
            url: "collegeList",
            dataType: "JSON",
            success: function (data) {
                if ($('#college').val() != '请选择所属学院') {
                    var college = $('#college').val();
                    $('#college option').remove();
                    $('#college').append("<option value='请选择所属学院'>请选择所属学院</option>");
                    $.each(data, function (a, b) {
                        if (college == b) $('#college').append("<option selected value='" + b + "'>" + b + "</option>");
                        else $('#college').append("<option value='" + b + "'>" + b + "</option>");
                    })
                }
                else {
                    $('#college option').remove();
                    $('#college').append("<option value='请选择所属专业'>请选择所属学院</option>");
                    $.each(data, function (a, b) {
                        $('#college').append("<option value='" + b + "'>" + b + "</option>");
                    })
                }

            }
        })


    })

    $('#college').change(function () {
        $('#major option').remove();
        $('#major').append("<option value='请选择所属专业'>请选择所属专业</option>");
        $('#classes option').remove();
        $('#classes').append("<option value='请选择所属班级'>请选择所属班级</option>");
    })
    //get major

    $('#major').hover(function () {

        if ($('#college').val() == '请选择所属学院') {
            $('#major option').remove();
            $('#major').append("<option value='请选择所属专业'>请选择所属专业</option>");
            $('#classes option').remove();
            $('#classes').append("<option value='请选择所属班级'>请选择所属班级</option>");
        }

        else {
            $.ajax({
                url: "majorList",
                dataType: "JSON",
                data: {"college": $('#college').val()},
                success: function (data) {

                    if ($('#major').val() != '请选择所属专业') {
                        var major = $('#major').val();
                        $('#major option').remove();
                        $('#major').append("<option value='请选择所属专业'>请选择所属专业</option>");


                        $.each(data, function (a, b) {
                            if (major == b) $('#major').append("<option selected value='" + b + "'>" + b + "</option>");
                            else $('#major').append("<option  value='" + b + "'>" + b + "</option>");
                        })
                    }
                    else {
                        $('#major option').remove();
                        $('#major').append("<option value='请选择所属专业'>请选择所属专业</option>");


                        $.each(data, function (a, b) {
                            $('#major').append("<option  value='" + b + "'>" + b + "</option>");
                        })
                    }

                }
            })
        }

    })

    $('#classes').hover(function () {
        if ($('#major').val() == '请选择所属专业') {
            $('#classes option').remove();
            $('#classes').append("<option value='请选择所属班级'>请选择所属班级</option>");
        }
        else {
            $.ajax({
                url: "classesList",
                dataType: "JSON",
                success: function (data) {

                    if ($('#classes').val() != '请选择所属班级') {
                        var classes = $('#classes').val();

                        $('#classes option').remove();
                        $('#classes').append("<option value='请选择所属班级'>请选择所属班级</option>");

                        $.each(data, function (a, b) {
                            if (classes == b) $('#classes').append("<option selected value='" + b + "'>" + b + "</option>");
                            else $('#classes').append("<option value='" + b + "'>" + b + "</option>");
                        })
                    }
                    else {
                        $('#classes option').remove();
                        $('#classes').append("<option value='请选择所属班级'>请选择所属班级</option>");

                        $.each(data, function (a, b) {
                            $('#classes').append("<option value='" + b + "'>" + b + "</option>")
                        })
                    }

                }
            })
        }
    })


</script>